package com.crab.business.example.service;

import com.crab.business.example.dao.CustomMapper;
import com.crab.business.example.dao.ExampleBeanMapper;
import com.crab.business.example.model.ExampleBean;
import com.crab.business.example.model.TestBean;
import com.crab.framework.mybatis.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * Created by liusk on 2016/7/27.
 */
@Slf4j
@Service
public class ExampleService extends BaseService<ExampleBean> {

    public List<ExampleBean> findByName(String username) {
        log.info("=============  begin ==============" + username);
        Example example = new Example(ExampleBean.class);
        example.createCriteria().andLike("username", "%" + username + "%");
        return mapper.selectByExample(example);
    }

    @Autowired
    private ExampleBeanMapper exampleBeanMapper;

    public List<ExampleBean> customMethod() {
        exampleBeanMapper.selectById();
        return this.selectByPage(1, 2, new Example(ExampleBean.class));
    }

    @Transactional
    public int insert() {
        mapper.insert(new ExampleBean());
        mapper.insert(new ExampleBean());
        return 1;
    }

    @Autowired
    private CustomMapper customMapper;

    public List<ExampleBean> getList(String username) {
        return customMapper.selectAll(username);
    }

}
